Skip to content

Refactor config dir to ~/.wvdsh and improve auth status#5

Merged
franzwarning merged 3 commits into
mainfrom
update-config-location-and-env
Jan 25, 2026
Merged

Refactor config dir to ~/.wvdsh and improve auth status#5
franzwarning merged 3 commits into
mainfrom
update-config-location-and-env

Conversation

@franzwarning
Copy link
Copy Markdown
Member

@franzwarning franzwarning commented Jan 25, 2026

Replaces use of platform-specific config directories with a unified ~/.wvdsh directory for credentials and cache. Enhances authentication logic to distinguish between environment variable and file-based credentials, updating the 'auth status' output accordingly. Also adds an AuthSource enum and removes the unused is_authenticated method.


Note

Consolidates app data under a single user dir and clarifies auth behavior.

  • Switches config/credentials/cache paths to ~/.wvdsh (replaces platform-specific dirs)
  • Auth now checks WVDSH_TOKEN first, then stored file; adds AuthSource and updates auth status messaging with masked token
  • Removes unused is_authenticated method
  • Updates dev TLS cert storage to ~/.wvdsh/dev-server and updater cache path accordingly
  • Bumps crate version to 0.1.47

Written by Cursor Bugbot for commit c3bd970. This will update automatically on new commits. Configure here.

Replaces use of platform-specific config directories with a unified ~/.wvdsh directory for credentials and cache. Enhances authentication logic to distinguish between environment variable and file-based credentials, updating the 'auth status' output accordingly. Also adds an AuthSource enum and removes the unused is_authenticated method.
@franzwarning
Copy link
Copy Markdown
Member Author

@claude review this

@claude
Copy link
Copy Markdown

claude Bot commented Jan 25, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 25, 2026

Claude finished @franzwarning's task in 1m 22s —— View job


Code Review

  • Gather context from PR changes
  • Review authentication changes (src/auth.rs)
  • Review config directory changes (src/config.rs)
  • Review main.rs changes for auth status output
  • Review other affected files
  • Provide comprehensive feedback

Summary

This PR makes a breaking change by migrating from platform-specific config directories to a unified ~/.wvdsh directory. While the implementation is solid, there are a few concerns about migration, security considerations, and code patterns that should be addressed.

🔴 Critical Issues

1. Missing Migration Path for Existing Users (src/config.rs:7-10, src/auth.rs:55-68)

The PR moves from platform-specific directories (managed by the directories crate's ProjectDirs) to ~/.wvdsh, but provides no migration path for existing users. Users who have stored credentials in the old location will suddenly appear as "not authenticated" after upgrading.

Impact: Users will need to re-authenticate and may lose stored credentials without warning.

Recommendation: Add migration logic that checks the old location on first use and moves credentials to the new location:

pub fn wvdsh_dir() -> Result<PathBuf> {
    let base_dirs = BaseDirs::new()
        .ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?;
    let new_dir = base_dirs.home_dir().join(".wvdsh");
    
    // One-time migration from old location
    migrate_from_old_location(&new_dir)?;
    
    Ok(new_dir)
}

fn migrate_from_old_location(new_dir: &Path) -> Result<()> {
    // Check if migration already happened
    if new_dir.exists() {
        return Ok(());
    }
    
    // Try to find old credentials
    if let Ok(old_dirs) = ProjectDirs::from("gg", "wavedash", "cli") {
        let old_creds = old_dirs.config_dir().join("credentials.json");
        if old_creds.exists() {
            fs::create_dir_all(new_dir)?;
            fs::copy(&old_creds, new_dir.join("credentials.json"))?;
            // Also migrate other files like update-cache.json, dev-server certs, etc.
        }
    }
    
    Ok(())
}

Fix this migration issue →

2. Duplicate Auth Retrieval Logic (src/auth.rs:55-86)

The get_api_key() and get_auth_source() methods duplicate the auth checking logic. get_auth_source() reads the file twice (once for checking, once to determine the source), which is inefficient and could lead to race conditions.

Issue: If credentials are deleted between the two method calls, inconsistent results may occur.

Recommendation: Refactor to check once and return structured data:

pub fn get_auth_info(&self) -> AuthInfo {
    // Check environment first
    if let Ok(api_key) = std::env::var("WVDSH_TOKEN") {
        if !api_key.is_empty() {
            return AuthInfo {
                source: AuthSource::Environment,
                api_key: Some(api_key),
            };
        }
    }
    
    // Check file
    if let Some(api_key) = self.read_file_credentials() {
        return AuthInfo {
            source: AuthSource::File,
            api_key: Some(api_key),
        };
    }
    
    AuthInfo {
        source: AuthSource::None,
        api_key: None,
    }
}

pub struct AuthInfo {
    pub source: AuthSource,
    pub api_key: Option<String>,
}

Fix auth duplication →

🟡 Moderate Issues

3. AuthSource Enum Should Derive Common Traits (src/auth.rs:13-17)

The AuthSource enum doesn't derive useful traits like Debug, Clone, Copy, PartialEq, which would be beneficial for testing and debugging.

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthSource {
    Environment,
    File,
    None,
}

4. Inconsistent Token Masking Logic (src/main.rs:118-123, 129-134)

The token masking logic is duplicated in both the Environment and File branches. This should be extracted to a helper function:

fn mask_token(token: &str) -> String {
    if token.len() > 10 {
        format!("{}...{}", &token[..6], &token[token.len() - 3..])
    } else {
        "***".to_string()
    }
}

5. Removal of is_authenticated() May Break Dependents (src/auth.rs:95-97)

The PR removes the is_authenticated() method. If any other code internally uses this method, it will break. Make sure to search the codebase for any references.

Verification needed: Run git grep 'is_authenticated' to check for usages.

🟢 Minor Issues & Style

6. Error Handling Could Be More Specific (src/config.rs:7-10)

The error message "Could not determine home directory" is generic. Consider being more specific about what might cause this (e.g., not set in environment, permission issues).

7. Consider Adding a Warning on First Migration

When users first upgrade and their credentials are migrated (or need re-auth), consider printing a user-friendly message explaining the change:

⚠️  Configuration directory has moved to ~/.wvdsh
   Your credentials have been migrated automatically.

8. .claude/settings.json Should Probably Be .gitignored (.claude/settings.json)

The new .claude/settings.json file contains project-specific Claude Code permissions. While it's useful for the team, consider whether this should be in .gitignore if it contains developer-specific or sensitive configurations. The fact that there's already a .claude/settings.local.json suggests a local/shared split pattern.

✅ What's Good

  1. Security: Unix file permissions (0o700 for directory, 0o600 for credentials file) are properly set in src/auth.rs:35, 49
  2. Environment Variable Priority: Checking WVDSH_TOKEN first is good for CI/CD use cases
  3. Clear User Messages: The auth status output clearly distinguishes between environment and file-based auth
  4. Consistent Path Updates: All affected files (updater, dev certs) were updated to use the new directory structure

Testing Recommendations

Before merging, test these scenarios:

  1. Fresh install with no existing credentials
  2. Upgrade from previous version with existing credentials in old location
  3. WVDSH_TOKEN environment variable set (should take priority)
  4. auth logout when using environment variable (should show appropriate message)
  5. Verify dev server certificates still work after migration

Introduced AuthInfo struct to encapsulate authentication source and API key. Refactored AuthManager to provide get_auth_info and improved API key retrieval logic. Added mask_token helper in main.rs to consistently mask tokens in status output.
@franzwarning franzwarning merged commit ed8f17a into main Jan 25, 2026
7 checks passed
@franzwarning franzwarning deleted the update-config-location-and-env branch January 25, 2026 21:39
@claude claude Bot mentioned this pull request Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant